package com.sq.subject.domain.handler.subject;

import com.sq.subject.common.enums.IsDeletedFlagEnum;
import com.sq.subject.common.enums.SubjectInfoTypeEnum;
import com.sq.subject.domain.bo.SubjectAnswerBO;
import com.sq.subject.domain.bo.SubjectInfoBO;
import com.sq.subject.infra.basic.entity.SubjectBrief;
import com.sq.subject.infra.basic.entity.SubjectJudge;
import com.sq.subject.infra.basic.service.SubjectBriefService;
import com.sq.subject.infra.basic.service.SubjectJudgeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 简答策略处理器
 * @author quan
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler {
    
    @Resource
    private SubjectBriefService subjectBriefService;
    
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.SIMPLE;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBo) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBo.getSubjectId().intValue());
        subjectBrief.setSubjectAnswer(subjectInfoBo.getSubjectAnswer());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectInfoBO query(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBO.getId().intValue());
        List<SubjectBrief> subjectBriefList = subjectBriefService.queryByCondition(subjectBrief);
        SubjectBrief brief = subjectBriefList.get(0);
        String subjectAnswer = brief.getSubjectAnswer();
        subjectInfoBO.setSubjectAnswer(subjectAnswer);
        return subjectInfoBO;
    }
}
